<?php

class ConfigAreas_Model extends Model {

    public function __construct(){
        parent::__construct();
    }

    public function getAreas ($idScheme) {
        if (isset ($idScheme)) {
            $query = "SELECT a.id, a.name, a.order ";
            $query .= "FROM area as a, scheme_area as sa ";
            $query .= "WHERE a.id = sa.id_area AND sa.id_scheme = $idScheme";
            return $this->_db->select ($query);
        }
        return null;
    }
    
    public function addArea ($name, $order, $idScheme) {
        $params = Array();
        $params['name'] = $name;
        $params['order'] = $order;
        $id = $this->_db->insert ('area', $params);
        
        $params2 = Array();
        $params2['id_area'] = $id;
        $params2['id_scheme'] = $idScheme;
        $this->_db->insert ('scheme_area', $params2);
        
        return true;
    }
    
    public function modifyArea ($id, $name, $order) {
        $params = Array();
        $where = Array();
        $params['name'] = $name;
        $params['order'] = $order;
        $where['id'] = $id;
        $this->_db->update ('area', $params, $where);
        
        return true;
    }
    
    public function removeArea ($id) {
        $this->_db->delete ('area', 'id = ' . $id);
        
        return true;
    }

}

?>